<?php

class WorkerController extends Controller
{

    /*
      * 获取工人列表
      *
      */
    public function actionGetWorkerList()
    {
        Util::log_normal($this,"start");
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //初始化
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql,"mobile","mobile"); //手机号
            $searchsql = Util::getSerarchStr($searchsql,"real_name","real_name"); //真实姓名
            $searchsql = Util::getSerarchStr($searchsql,"idcard","idcard"); //身份证
            $searchsql = Util::getSerarchStr($searchsql,"worker_num","worker_num"); //工号

            //获取count
            $totalcount = Worker::model()->count($searchsql);



            //排序
            $searchsql = $searchsql." order by worker_id desc";
            //加上分页控制
            $searchsql = Util::addLimitSql($searchsql);

            //Util::responseMsg($searchsql);

            //获取list
            $userlist = Worker::model()->findAll($searchsql);



            // Util::responseObj(MsgConst::RETURN_SUCCESS);
            Util::responseList($totalcount,$userlist);


        }catch (Exception $e)
        {
            Yii::log($e->getMessage(), 'error', '');

            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
     * 获取工人审核信息
     *
     */
    public function actionGetWorkerRequestList()
    {
        Util::log_normal($this,"start");
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //初始化
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql,"mobile","mobile"); //手机号
            $searchsql = Util::getSerarchStr($searchsql,"status","status"); //手机号

            //获取count
            $totalcount = WorkerVerifyRequest::model()->count($searchsql);



            //排序
            $searchsql = $searchsql." order by request_id desc";
            //加上分页控制
            $searchsql = Util::addLimitSql($searchsql);

            //Util::responseMsg($searchsql);

            //获取list
            $userlist = WorkerVerifyRequest::model()->findAll($searchsql);



            // Util::responseObj(MsgConst::RETURN_SUCCESS);
            Util::responseList($totalcount,$userlist);


        }catch (Exception $e)
        {
            Yii::log($e->getMessage(), 'error', '');

            Util::responseErrorMsg($e->getMessage());

        }
    }


    /*
     * 同意审核
     */
    public function actionAcceptRequest()
    {

        Util::log_normal($this,"start");
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数
            $request_id = Util::getParamNotEmpty("request_id");
            $reason = Util::getParam("reason","认证通过");


            $vrequest = WorkerVerifyRequest::model()->findByPK($request_id);

            Util::checkExistAndNotDelete($vrequest);

            $worker = Worker::model()->findByPK($vrequest->worker_id);

            Util::checkExistAndNotDelete($worker);

            //同意
            WorkerService::acceptRequest($vrequest,$worker,$reason);

            //返回
            Util::responseMsg(MsgConst::RETURN_SUCCESS);



        }catch (Exception $e)
        {
            Yii::log($e->getMessage(), 'error', '');

            Util::responseErrorMsg($e->getMessage());

        }

    }

    /*
     * 拒绝审核
     */
    public function actionDenyRequest()
    {

        Util::log_normal($this,"start");
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数
            $request_id = Util::getParamNotEmpty("request_id");
            $reason = Util::getParamNotEmpty("reason");


            $vrequest = WorkerVerifyRequest::model()->findByPK($request_id);

            Util::checkExistAndNotDelete($vrequest);

            $worker = Worker::model()->findByPK($vrequest->worker_id);

            Util::checkExistAndNotDelete($worker);

            //拒绝
            WorkerService::denyRequest($vrequest,$worker,$reason);

            //返回
            Util::responseMsg(MsgConst::RETURN_SUCCESS);



        }catch (Exception $e)
        {
            Yii::log($e->getMessage(), 'error', '');

            Util::responseErrorMsg($e->getMessage());

        }

    }

    /*
     * 获取请求对应的处理log
     *
     */

    public function actiongetRequestLogList()
    {

        Util::log_normal($this,"start");
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数
            $request_id = Util::getParamNotEmpty("request_id");


            $vrequest = WorkerVerifyRequest::model()->findByPK($request_id);

            Util::checkExistAndNotDelete($vrequest);

            //初始化
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql,"request_id","request_id"); //请求id

            $list = WorkerVerifyRequestLog::model()->findAll($searchsql);



            //返回
            Util::responseList(count($list),$list);



        }catch (Exception $e)
        {
            Yii::log($e->getMessage(), 'error', '');

            Util::responseErrorMsg($e->getMessage());

        }

    }

    //服务项目

    /*
    * 添加
    *
    */
    public function actionAddWorkerService()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $type_name = Util::getParamNotEmpty("type_name");
            $type_id = Util::getParamNotEmpty("type_id");
            $service_name = Util::getParamNotEmpty("service_name");




            //添加
            $obj = new  WorkerServiceproj();
            Util::initObjData($obj);


            $obj->type_name = $type_name;
            $obj->type_id = $type_id;
            $obj->service_name = $service_name;


            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 删除
    */
    public function actionDeleteWorkerService()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");


            //删除
            $obj = WorkerServiceproj::model()->findByPK($obj_id);

                    Util::checkExistAndNotDelete($obj);

                    Util::deleteObjData($obj);

                    Util::saveObjData($obj);



                    //返回数据
                    Util::responseMsg(MsgConst::RETURN_SUCCESS);


                } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取列表分页
    *
    */
    public function actionGetWorkerServiceListPaging()
    {

        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数

            $type_id = Util::getParamNotEmpty("type_id");


            $searchsql = Util::initSearchSql();

            $searchsql=Util::getSerarchStr($searchsql,"type_id","type_id");


            //获取count
            $totalcount = WorkerServiceproj::model()->count($searchsql);

                //排序
                $searchsql = $searchsql . " order by create_time desc";

                //加上分页控制
                $searchsql = Util::addLimitSql($searchsql);

                //获取list
                $list = WorkerServiceproj::model()->findAll($searchsql);


                Util::responseList($totalcount, $list);

            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }


    }

    /*
    * 获取设计师列表分页
    *
    */
    public function actionGetDesignerListPaging()
    {

        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数

            $type_id = Util::getParamNotEmpty("type_id");


            $searchsql = Util::initSearchSql();

            $searchsql=Util::getSerarchStr($searchsql,"type_id","type_id");


            //获取count
            $totalcount = Worker::model()->count($searchsql);

            //排序
            $searchsql = $searchsql . " order by create_time desc";

            //加上分页控制
            $searchsql = Util::addLimitSql($searchsql);

            //获取list
            $list = Worker::model()->findAll($searchsql);

            //去掉设计师账户密码
            foreach($list as $key => $value){
                $list[$key] = WorkerService::formatWorker($list[$key]);
            }



            Util::responseList($totalcount, $list);

        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }


    }




}


?>